package exercise;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

// https://leetcode.cn/problems/minimum-time-difference/
public class L230704_I {
    public int findMinDifference(List<String> timePoints) {
        // 鸽巢原理
        if (timePoints.size() > 1440) {
            return 0;
        }
        List<Integer> min = new ArrayList<>();
        for (String s : timePoints) {
            min.add(Integer.parseInt(s.split(":")[0])*60 + Integer.parseInt(s.split(":")[1]));
        }
        Collections.sort(min);

        int pos1 = 0;
        int pos2 = 1;
        int ans = min.get(0) + 24*60 - min.get(min.size()-1);

        while (pos2 < min.size()) {
            ans = Math.min(ans, min.get(pos2) - min.get(pos1));
            pos2++;
            pos1++;
        }

        return ans;
    }

    public static void main(String[] args) {
        L230704_I s = new L230704_I();
        List<String> list = new ArrayList<>();

        list.add("12:13");
//        list.add("00:00");
        list.add("00:12");

        System.out.println(s.findMinDifference(list));
    }
}
